#include "snode.h"
#include <QRadialGradient>
#include "sege.h"
//
class SStructure;

SNode::SNode(QString id ) 
	: QGraphicsEllipseItem()
{
	
	setFlag(QGraphicsItem::ItemIsMovable);
	
	QRadialGradient gradient(25, 25, 75, 25, 25);
    gradient.setColorAt(0, QColor::fromRgbF(0, 1, 0, 1));
    gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));

    QBrush brush(gradient);
	
	setBrush(brush);
	
	setRect(-25,-25,50,50);
	
	Label = new QGraphicsTextItem();
	Label->setHtml(id);
	Label->setParentItem(this);
	
}

void SNode::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
	QGraphicsItem::mouseReleaseEvent(mouseEvent);
	updeteEges();
	
}

void SNode::mouseMoveEvent (QGraphicsSceneMouseEvent *mouseEvent)
{
	QGraphicsItem::mouseMoveEvent(mouseEvent);
	updeteEges();
	
}

void SNode::updeteEges()
{
	QMap<QString,SEge*>::iterator i = from.begin();
	while (i != from.end()) 
		{
			i.value()->updateControls(); 
			++i;
		}
		
	QMap<QString,SEge*>::iterator j = to.begin();
	while (j != to.end()) 
		{
			j.value()->updateControls(); 
			++j;
		}
}

